package com.demo.springBoot2.config.satoken;

import cn.dev33.satoken.stp.StpInterface;
import com.demo.springBoot2.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 *
 * @Author pl711@qq.com
 * @PackageName springBoot2
 * @Package com.demo.springBoot2.anno
 * @Version 1.0
 *   @Date: 2024/4/9-04-09-19:21
 *   此类用于获取用户在数据库中的角色和权限
 *
 */
@Component
public class StpInterfaceImpl  implements StpInterface {

    @Autowired
    private IRoleService iRoleService;

    /**
     * 返回一个账号所拥有的权限码集合
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        return iRoleService.selectUserPermissionsById(Integer.parseInt(loginId.toString()));
    }

    /**
     * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
     * loginId登录这个人的id
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        return iRoleService.selectUserRoleById(Integer.parseInt(loginId.toString()));
    }
}
